import React from 'react';
import AuthorizedButton from '@/components/AuthorizedButton';
import { Button } from 'antd';
import { router } from 'umi';
import ReturnMoneyCoefficient from './ReturnMoneyCoefficient';
import ViewOverallOverview from './ViewOverallOverview';

export function PageExtra({ handleStartApproval, ...restProps }) {
  return (
    <div className="operation">
      <AuthorizedButton authority="business_returnMoneyPlan_startApproval">
        <Button type="primary" onClick={handleStartApproval}>
          发起审批
        </Button>
      </AuthorizedButton>
      <AuthorizedButton authority="business_returnMoneyPlan_approvedRecord">
        <Button
          onClick={() =>
            router.push(
              `/OperatingPlan/ReturnMoneyPlan/ProjectValue/${restProps.match.params.project}`,
            )
          }
        >
          审批记录
        </Button>
      </AuthorizedButton>
    </div>
  );
}

// 回款计划分期版本新建按钮
export function TabBarExtraContent(props) {
  const { match, handlerUnusualCreate, handlerCreate, unusualLoading, createLoading } = props;
  // 战规版，投资版显示异常创建按钮
  const IS_UNUSUAL = match.params.category === 'investment' || match.params.category === 'strategy';
  return (
    <div className="operation">
      {IS_UNUSUAL && (
        <AuthorizedButton authority="business_returnMoneyPlan_unusualCreate">
          <Button className="red-button" onClick={handlerUnusualCreate} loading={unusualLoading}>
            异常新建版本
          </Button>
        </AuthorizedButton>
      )}
      {match.params.category !== 'budget' && (
        <AuthorizedButton authority="business_returnMoneyPlan_createVersion">
          <Button type="primary" onClick={handlerCreate} loading={createLoading}>
            新建版本
          </Button>
        </AuthorizedButton>
      )}
    </div>
  );
}

export function PageRight({
  handleSetAssessment,
  handlerDelete,
  handleExportReportForm,
  handlerViewApproved,
  viewApprovedLoading,
  currentVersion,
  deleteLoading,
  setBudgetLoading,
  assessmentLoading,
  handlersetBudgetVersion,
  handlercopyBudgetVersion,
  match,
}) {
  return (
    <div className="operation">
      {currentVersion.versionType !== 'budget' ? (
        <AuthorizedButton authority="business_returnMoneyPlan_setBudgetVertion">
          <Button
            onClick={handlersetBudgetVersion}
            loading={setBudgetLoading}
            className="red-button"
          >
            设置为预算版
          </Button>
        </AuthorizedButton>
      ) : (
        <AuthorizedButton authority="business_returnMoneyPlan_copyBudgetVertion">
          <Button
            onClick={handlercopyBudgetVersion}
            loading={setBudgetLoading}
            className="red-button"
          >
            复制预算版
          </Button>
        </AuthorizedButton>
      )}
      {currentVersion.versionType === 'investment' && currentVersion.isAssessmentVersion * 1 === 0 && (
        <AuthorizedButton authority="business_returnMoneyPlan_setAssessment">
          <Button onClick={handleSetAssessment} loading={assessmentLoading} className="red-button">
            设为考核版
          </Button>
        </AuthorizedButton>
      )}
      {/* <AuthorizedButton authority="RemovalRateForm_Export"> */}
      {/* 回款系数 */}
      <ReturnMoneyCoefficient versionId={match.params.version} />
      {/* </AuthorizedButton> */}
      <AuthorizedButton authority="business_returnMoneyPlan_stagingExportReport">
        <Button className="yellow-button" onClick={handleExportReportForm}>
          导出报表
        </Button>
      </AuthorizedButton>
      {(currentVersion.versionStateCode === 'examined_approved' ||
        currentVersion.versionStateCode === 'approved' ||
        currentVersion.versionStateCode === 'failure_approved' ||
        currentVersion.versionStateCode === 'success_approved') && (
        <AuthorizedButton authority="business_returnMoneyPlan_viewApproved">
          <Button
            className="yellow-button"
            onClick={handlerViewApproved}
            loading={viewApprovedLoading}
          >
            查看审批
          </Button>
        </AuthorizedButton>
      )}
      {(currentVersion.versionStateCode === 'not_prepared' ||
        currentVersion.versionStateCode === 'organization') && (
        <AuthorizedButton authority="business_returnMoneyPlan_deleteVersion">
          <Button onClick={handlerDelete} loading={deleteLoading}>
            删除版本
          </Button>
        </AuthorizedButton>
      )}
    </div>
  );
}

export function EditPageRight(props) {
  const { isEdit, handlerIsEdit, match } = props;
  return (
    <div className="operation">
      {/* <AuthorizedButton authority="RemovalRateForm_Export"> */}
      {/* // 回款系数 */}
      <ReturnMoneyCoefficient versionId={match.params.version} />
      {/* </AuthorizedButton> */}
      <AuthorizedButton authority="business_returnMoneyPlan_editVersion">
        <Button type="primary" onClick={handlerIsEdit}>
          {isEdit ? '取消调整' : '调整回款'}
        </Button>
      </AuthorizedButton>
      {/* <AuthorizedButton authority="RemovalRateForm_Export"> */}
      <ViewOverallOverview {...props} />
      {/* </AuthorizedButton> */}
    </div>
  );
}
